/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avl.sv.shared;

import avl.sv.shared.sources.SlideSource;
import avl.sv.shared.Annotations.Annotation;
import avl.sv.shared.Annotations.AnnotationSet;
import avl.sv.shared.Annotations.ROI;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ProgressMonitor;

/**
 *
 * @author benbryan
 */
public class SampleSetClass {
    public final String className;
    public ArrayList<Sample> samples;

    public SampleSetClass(String className) {
        this.className = className;
    }   
       
    public static ArrayList<SampleSetClass> generateTrainingSets(ArrayList<SlideSource> slideSources, Solution solution, ProgressMonitor pm){
        int count = 0; 
        ArrayList<SampleSetClass> samplesSets = new ArrayList<>();
        for (ClassifierClass c : solution.getClasses()) {
            ArrayList<Sample> samples = new ArrayList<>();
            for (AnnotationSet annoSet : c.getAnnotationSets()) {
                if (pm != null){
                    SlideReference sr = annoSet.getSlideReference();
                    pm.setNote(sr.slideSetName +"\\"+ sr.slideName);
                }
                SlideSource slideSource = ImageID.getSlideSourceForHash(slideSources, annoSet.getHash());
                SampleSetSlide samplesSet = new SampleSetSlide(slideSource, annoSet, solution);
                //TODO: check server for existing features
                count = samplesSet.getSampleFeatures(count, solution, pm);
                if (pm != null){
                    if (pm.isCanceled()){
                        return null;
                    }
                }
                samples.addAll(samplesSet.samples);
            }
            SampleSetClass samplesSet = new SampleSetClass(c.className);
            samplesSet.samples = samples;
            samplesSets.add(samplesSet);
        }
        return samplesSets;
    }

    public static int numelSamples(Solution solution, ArrayList<SlideSource> slideSources) {
        int count = 0;
        for (ClassifierClass c : solution.getClasses()) {
            for (AnnotationSet annoSet : c.getAnnotationSets()) {
                SlideSource ss = SlideSource.getSlideSourceForHash(slideSources, annoSet.getHash());
                SampleSetSlide samplesSet = new SampleSetSlide( ss, annoSet, solution);
                count += samplesSet.samples.size();
            }
        }
        return count;
    }
   
    
}
